package demo.java.lang.management.jvm;

import java.io.Serializable;
import java.lang.management.ManagementFactory;
import java.util.List;
import java.util.Map;

public class AppTraceConfig implements Serializable {

    private static final long serialVersionUID = -5701652021089915519L;
    private String appName;
    private String hostName;
    private String ip;
    private String company;
    private String secLevel;
    private String processId;
    private boolean sampleSwitch;
    private double sampFrequency;
    private int sampBaseline;
    private Long delayTime;
    private Long flushSize;
    private Integer queueSize;
    private static AppTraceConfig appTraceConfig = new AppTraceConfig();
    private String[] urlPatterns;
    private boolean xdcsSwitch = true;
    private boolean taskSwitch = true;
    private String eventType;
    private Map<String, String> url2eventMapping;
    private Map<String, String> url2AppNameMapping;
    private Map<String, String> urlContain2eventMapping;
    private Map<String, String> personalUrlMapping;
    private Map<String, String> log2SizeMapping;
    private List<String> whiteList;

    private String logIdentityAndEventTypeKeys;

    private List<String> urlExcludeList;
    private String environmentId;
    private String logDir;
    private String metricSpanTime;

    private boolean hasXdcsPropFile = true;
    private int distinctMaxService;
    private boolean writeMainstayLog = true;

    private static boolean initSuccess = false;

    private boolean taskAOP = false;//task项目的AOP配置，不需要parentSpan就可落盘

    private boolean xuid = false;//新的uid生成

    private boolean autoLogMainstayTimeout = true;//自动落盘client端的mainstay超时错误
    private List<String> spanToLogServiceIds;

    private int writeQueueSize = 4096;

    static {
        appTraceConfig.setAppName(XdcsPropertiesParser.getApp());
        appTraceConfig.setHostName(XdcsPropertiesParser.getHostName());
        appTraceConfig.setIp(XdcsPropertiesParser.getIp());
        appTraceConfig.setSampleSwitch(XdcsPropertiesParser.getSampleSwitch());
        appTraceConfig.setSampFrequency(XdcsPropertiesParser.getSampleFrequency());
        appTraceConfig.setSampBaseline(XdcsPropertiesParser.getSampleBaseline());
        appTraceConfig.setXdcsSwitch(XdcsPropertiesParser.getSwitch());
        appTraceConfig.setTaskSwitch(XdcsPropertiesParser.getTaskSwitch());
        appTraceConfig.setHasXdcsPropFile(XdcsPropertiesParser.isHasXdcsPropFile());
        appTraceConfig.setCompany("ximalaya");
        appTraceConfig.setProcessId(ManagementFactory.getRuntimeMXBean().getName());
        appTraceConfig.setSecLevel("1");
        appTraceConfig.setEventType(XdcsPropertiesParser.getEventType());
        appTraceConfig.setUrl2eventMapping(XdcsPropertiesParser.getUrlMapping());
        appTraceConfig.setUrl2AppNameMapping(XdcsPropertiesParser.getUrlAppNameMapping());
        appTraceConfig.setUrlPatterns(XdcsPropertiesParser.getUrlPatterns());
        appTraceConfig.setLog2SizeMapping(XdcsPropertiesParser.getLogSizeMapping());
        appTraceConfig.setUrlContain2eventMapping(XdcsPropertiesParser.getUrlContainMapping());
        appTraceConfig.setUrlExcludeList(XdcsPropertiesParser.getUrlExcludeList());
        appTraceConfig.setEnvironmentId(XdcsPropertiesParser.getEnvironmentId());
        appTraceConfig.setLogDir(XdcsPropertiesParser.getLogDir());
        appTraceConfig.setPersonalUrlMapping(XdcsPropertiesParser.getPersonalUrlMapping());
        appTraceConfig.setMetricSpanTime(XdcsPropertiesParser.getMetricSpanTime());
        appTraceConfig.setWhiteList(XdcsPropertiesParser.getXdcsWhiteList());
        appTraceConfig.setDistinctMaxService(XdcsPropertiesParser.getDistinctMaxServiceNum());
        appTraceConfig.setTaskAOP(XdcsPropertiesParser.isTaskAOP());
        appTraceConfig.setXuid(XdcsPropertiesParser.isXUID());
        appTraceConfig.setAutoLogMainstayTimeout(XdcsPropertiesParser.isAutoLogMainstayTimeout());
        appTraceConfig.setLogIdentityAndEventTypeKeys(XdcsPropertiesParser.getLogIdentityAndEventTypeKeys());
        appTraceConfig.setWriteMainstayLog(XdcsPropertiesParser.getWriteMainstayLog());
        appTraceConfig.setSpanToLogServiceIds(XdcsPropertiesParser.getSpanToLogServiceIds());
        appTraceConfig.setWriteQueueSize(XdcsPropertiesParser.getWriteQueueSize());
        initSuccess = true;
    }

    /**
     * @return the log2SizeMapping
     */
    public Map<String, String> getLog2SizeMapping() {

        return log2SizeMapping;
    }


    /**
     * @param log2SizeMapping the log2SizeMapping to set
     */
    public void setLog2SizeMapping(Map<String, String> log2SizeMapping) {

        this.log2SizeMapping = log2SizeMapping;
    }

    public boolean isAutoLogMainstayTimeout() {
        return autoLogMainstayTimeout;
    }

    public void setAutoLogMainstayTimeout(boolean autoLogMainstayTimeout) {
        this.autoLogMainstayTimeout = autoLogMainstayTimeout;
    }

    public boolean isTaskAOP() {
        return taskAOP;
    }

    public void setTaskAOP(boolean taskAOP) {
        this.taskAOP = taskAOP;
    }

    public static boolean isInitSuccess() {
        return initSuccess;
    }

    public int getDistinctMaxService() {
        return distinctMaxService;
    }

    public void setDistinctMaxService(int distinctMaxService) {
        this.distinctMaxService = distinctMaxService;
    }

    public boolean isHasXdcsPropFile() {
        return hasXdcsPropFile;
    }

    public void setHasXdcsPropFile(boolean hasXdcsPropFile) {
        this.hasXdcsPropFile = hasXdcsPropFile;
    }

    /**
     * @return the metricSpanTime
     */
    public String getMetricSpanTime() {

        return metricSpanTime;
    }


    /**
     * @param metricSpanTime the metricSpanTime to set
     */
    public void setMetricSpanTime(String metricSpanTime) {

        this.metricSpanTime = metricSpanTime;
    }


    /**
     * @return the logDir
     */
    public String getLogDir() {

        return logDir;
    }


    /**
     * @param logDir the logDir to set
     */
    public void setLogDir(String logDir) {

        this.logDir = logDir;
    }

    public String[] getUrlPatterns() {
        return urlPatterns;
    }

    public void setUrlPatterns(String[] urlPatterns) {
        this.urlPatterns = urlPatterns;
    }

    public String getAppName() {
        return appName;
    }

    public void setAppName(String appName) {
        this.appName = appName;
    }

    public String getHostName() {
        return hostName;
    }

    public void setHostName(String hostName) {
        this.hostName = hostName;
    }

    public String getCompany() {
        return company;
    }

    public void setCompany(String company) {
        this.company = company;
    }

    public String getSecLevel() {
        return secLevel;
    }

    public void setSecLevel(String secLevel) {
        this.secLevel = secLevel;
    }

    /**
     * @return the eventType
     */
    public String getEventType() {

        return eventType;
    }


    /**
     * @param eventType the eventType to set
     */
    public void setEventType(String eventType) {

        this.eventType = eventType;
    }


    /**
     * @return the url2eventMapping
     */
    public Map<String, String> getUrl2eventMapping() {

        return url2eventMapping;
    }


    /**
     * @param url2eventMapping the url2eventMapping to set
     */
    public void setUrl2eventMapping(Map<String, String> url2eventMapping) {

        this.url2eventMapping = url2eventMapping;
    }


    /**
     * @return the url2AppNameMapping
     */
    public Map<String, String> getUrl2AppNameMapping() {

        return url2AppNameMapping;
    }

    /**
     * @param url2AppNameMapping the url2AppNameMapping to set
     */
    public void setUrl2AppNameMapping(Map<String, String> url2AppNameMapping) {

        this.url2AppNameMapping = url2AppNameMapping;
    }


    public String getIp() {
        return ip;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }

    public boolean getSampleSwitch() {
        return sampleSwitch;
    }

    public void setSampleSwitch(boolean sampleSwitch) {
        this.sampleSwitch = sampleSwitch;
    }

    public double getSampFrequency() {
        return sampFrequency;
    }

    public void setSampFrequency(double sampFrequency) {
        this.sampFrequency = sampFrequency;
    }

    public Long getDelayTime() {
        return delayTime;
    }

    public void setDelayTime(Long delayTime) {
        this.delayTime = delayTime;
    }

    public Long getFlushSize() {
        return flushSize;
    }

    public void setFlushSize(Long flushSize) {
        this.flushSize = flushSize;
    }

    public Integer getQueueSize() {
        return queueSize;
    }

    public void setQueueSize(Integer queueSize) {
        this.queueSize = queueSize;
    }

    public String getProcessId() {
        return processId;
    }

    public void setProcessId(String processId) {
        this.processId = processId;
    }

    public boolean isXdcsSwitch() {
        return xdcsSwitch;
    }

    public void setXdcsSwitch(boolean xdcsSwitch) {
        this.xdcsSwitch = xdcsSwitch;
    }

    public AppTraceConfig getAppTraceConfig() {
        return appTraceConfig;
    }

    public static AppTraceConfig getLocalConfig() {
        return appTraceConfig;
    }


    /**
     * @return the urlContain2eventMapping
     */
    public Map<String, String> getUrlContain2eventMapping() {

        return urlContain2eventMapping;
    }


    /**
     * @param urlContain2eventMapping the urlContain2eventMapping to set
     */
    public void setUrlContain2eventMapping(Map<String, String> urlContain2eventMapping) {

        this.urlContain2eventMapping = urlContain2eventMapping;
    }

    public String getEnvironmentId() {
        return environmentId;
    }

    public void setEnvironmentId(String environmentId) {
        this.environmentId = environmentId;
    }

    public List<String> getUrlExcludeList() {
        return urlExcludeList;
    }

    public void setUrlExcludeList(List<String> urlExcludeList) {
        this.urlExcludeList = urlExcludeList;
    }

    /**
     * @return the personalUrlMapping
     */
    public Map<String, String> getPersonalUrlMapping() {

        return personalUrlMapping;
    }


    /**
     * @param personalUrlMapping the personalUrlMapping to set
     */
    public void setPersonalUrlMapping(Map<String, String> personalUrlMapping) {

        this.personalUrlMapping = personalUrlMapping;
    }

    public int getSampBaseline() {
        return sampBaseline;
    }

    public void setSampBaseline(int sampBaseline) {
        this.sampBaseline = sampBaseline;
    }


    /**
     * @return the whiteList
     */
    public List<String> getWhiteList() {

        return whiteList;
    }


    /**
     * @param whiteList the whiteList to set
     */
    public void setWhiteList(List<String> whiteList) {

        this.whiteList = whiteList;
    }

    public String getLogIdentityAndEventTypeKeys() {
        return logIdentityAndEventTypeKeys;
    }

    public void setLogIdentityAndEventTypeKeys(String logIdentityAndEventTypeKeys) {
        this.logIdentityAndEventTypeKeys = logIdentityAndEventTypeKeys;
    }

    public boolean isWriteMainstayLog() {
        return writeMainstayLog;
    }

    public void setWriteMainstayLog(boolean writeMainstayLog) {
        this.writeMainstayLog = writeMainstayLog;
    }

    public List<String> getSpanToLogServiceIds() {
        return spanToLogServiceIds;
    }

    public void setSpanToLogServiceIds(List<String> spanToLogServiceIds) {
        this.spanToLogServiceIds = spanToLogServiceIds;
    }

    public int getWriteQueueSize() {
        return writeQueueSize;
    }

    public void setWriteQueueSize(int writeQueueSize) {
        this.writeQueueSize = writeQueueSize;
    }


    /**
     * @return the taskSwitch
     */
    public boolean isTaskSwitch() {

        return taskSwitch;
    }


    /**
     * @param taskSwitch the taskSwitch to set
     */
    public void setTaskSwitch(boolean taskSwitch) {

        this.taskSwitch = taskSwitch;
    }


    /**
     * @return the xuid
     */
    public boolean isXuid() {

        return xuid;
    }


    /**
     * @param xuid the xuid to set
     */
    public void setXuid(boolean xuid) {

        this.xuid = xuid;
    }

}
